import java.awt.*;

// 抗体类
class Antibody {
    float x, y;
    float angle;
    float speed = 7f;
    int size = 14;
    float lifetime = 1.5f;
    int worldWidth, worldHeight;

    public Antibody(float x, float y, float angle, int worldWidth, int worldHeight) {
        this.x = x;
        this.y = y;
        this.angle = angle;
        this.worldWidth = worldWidth;
        this.worldHeight = worldHeight;
    }

    public boolean update() {
        x += (float) (Math.cos(angle) * speed);
        y += (float) (Math.sin(angle) * speed);
        lifetime -= 1 / 60f;
        return lifetime > 0 &&
                x > (float) size / 2 && x < worldWidth - (float) size / 2 &&
                y > (float) size / 2 && y < worldHeight - (float) size / 2;
    }

    public void draw(Graphics2D g) {
        // Y形抗体绘制
        g.setColor(new Color(255, 240, 100, 220));

        // 主干
        float endX = x + (float) Math.cos(angle) * size;
        float endY = y + (float) Math.sin(angle) * size;
        g.setStroke(new BasicStroke(3));
        g.drawLine((int) x, (int) y, (int) endX, (int) endY);

        // 分叉臂
        float armAngle1 = angle + (float) Math.PI / 4;
        float armAngle2 = angle - (float) Math.PI / 4;
        float armLength = size * 0.7f;

        g.drawLine((int) x, (int) y,
                (int) (x + Math.cos(armAngle1) * armLength),
                (int) (y + Math.sin(armAngle1) * armLength));
        g.drawLine((int) x, (int) y,
                (int) (x + Math.cos(armAngle2) * armLength),
                (int) (y + Math.sin(armAngle2) * armLength));

        // 中心点
        g.fillOval((int) x - 3, (int) y - 3, 6, 6);
    }
}
